package com.zycfc.zsf.boot.mybatis.typehandler;

import org.apache.ibatis.type.*;
import org.springframework.util.*;
import java.sql.*;

public class StringArrayTypeHandler extends BaseTypeHandler<String[]>
{
    private final String delimiter;
    
    public StringArrayTypeHandler() {
        this.delimiter = ",";
    }
    
    public StringArrayTypeHandler(final String delimiter) {
        this.delimiter = delimiter;
    }
    
    public void setNonNullParameter(final PreparedStatement ps, final int i, final String[] parameter, final JdbcType jdbcType) throws SQLException {
        ps.setString(i, StringUtils.arrayToDelimitedString((Object[])parameter, this.delimiter));
    }
    
    public String[] getNullableResult(final ResultSet rs, final String columnName) throws SQLException {
        final String str = rs.getString(columnName);
        if (rs.wasNull()) {
            return null;
        }
        return StringUtils.tokenizeToStringArray(str, this.delimiter);
    }
    
    public String[] getNullableResult(final ResultSet rs, final int columnIndex) throws SQLException {
        final String str = rs.getString(columnIndex);
        if (rs.wasNull()) {
            return null;
        }
        return StringUtils.tokenizeToStringArray(str, this.delimiter);
    }
    
    public String[] getNullableResult(final CallableStatement cs, final int columnIndex) throws SQLException {
        final String str = cs.getString(columnIndex);
        if (cs.wasNull()) {
            return null;
        }
        return StringUtils.tokenizeToStringArray(str, this.delimiter);
    }
}
